// app.js
import {getUserInfo} from './api/api'
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    

    // 全局查看用户信息
    this.globalData.loginPromise = getUserInfo().then(res=>{
      // console.log(res);
      if(res.data.code === 0){
        console.log("登录.....");
        this.globalData.isLogin = true;
        this.globalData.userInfo = res.data.data
      }else {
        console.log("未登录.....");
        this.globalData.isLogin = false;
        this.globalData.userInfo = null
      }
    }) 

  },
  globalData: {
    userInfo: null,
    loginPromise:null,
    isLogin:null
  }
})
